<?php

class Data {

    public static $_shop_number_page = 5;
    public static $_number_page = 10; 
    public static $_pic_path = "webroot/file/";
    public static $VERSION = 10;

    # 门店营业状态
    public static $_store_business_status = array(1 => "待维护",2 => "营业中",3 => "关店",4 => "不接单", 5 => "装修中");

    # 订单指派
    public static $_express_type= array('self' => "自建骑手", 'sf' => "顺丰", 'dd' => "达达", 'ss' =>"闪送", 'jrd' =>"今日达", 'uu' =>"UU跑腿", 'slw' =>"365跑腿");
    public static $_express_type_shop= array('self' => "自建骑手", 'sf' => "顺丰", 'dd' => "达达", 'ss' =>"闪送", 'jrd' =>"今日达", 'uu' =>"UU跑腿", 'slw' =>"365跑腿");
    public static $_express_type_admin= array('self' => "自建骑手", 'sf' => "顺丰", 'dd' => "达达", 'ss' =>"闪送", 'jrd' =>"今日达", 'uu' =>"UU跑腿", 'slw' =>"365跑腿");
    public static $jrd_type= array('1' => "机动车", '2' => "电动车");

    public static $_shop_delivery_time_name=array('self' => "预计送达时间", 'sf' => "预计送达时间", 'dd' => "发单时间", 'ss' =>"取件时间", 'jrd' =>"取件时间");
    # 指派单状态
//    public static $_express_status= array(0 => "推送失败",1 => "未推送",2 => "指派单推送",3 => "派单中", 4 => "配送中", 5 => "完成订单", 6 => "取消订单", 7=> "门店取消订单");
    public static $_express_status= array(0 => "推送失败",1 => "未推送",2 => "指派单推送",3 => "派单中", 4 => "配送中", 5 => "完成订单",6 => "异常订单", 7=> "门店订单异常处理", 8=> "第三方取消或门店手动取消订单"); // 10-31修改规则

    # 订单状态
    public static $_order_status= array(-1 => "不显示",0 => "待指派",1 => "未推送",2 => "待接单",3 => "待取货", 4 => "配送中", 5 => "配送完成", 6 => "异常" );//订单状态  后台专用
    public static $_order_status_admin= array(-1 => "不显示",1 => "未推送",2 => "待接单",3 => "待取货", 4 => "配送中", 5 => "配送完成", 6 => "异常" );//订单状态 后台专用

    # 删除理由
    public static $_order_del = array("距离异常，宅配APP发单","无人接单，宅配APP发单", "快递邮寄","到店自提" );

    #快递代码
    public static $_express_code= array( 5001 => "顺丰", 5002 => "达达",5003 => "人人", 5004 =>"闪送");

    # 直辖市
    public static $_city_code= array("上海","北京","天津","重庆");

    # 异常订单状态
    public static $_eorder_status_code= array(7=>"已处理",6=>"未处理");

    # 湖南分司 蛋糕类型 仅顺丰
    public static $_sf_push_type_for_hunan= array(13=>"蛋糕",99=>"其他");
    public static $_dd_direct_delivery = array("普通配送","专人直送");

    # 骑手审核状态
    public static $_riders_status_code_search= array(1=>"启用",2=>"禁用");
    public static $_riders_status_code= array(0=>"待审核",1=>"启用",2=>"禁用",3=>"未通过",4=>"骑手风控状态禁止接单");
    public static $_orders_source= array(1001=>"美团",1002=>"POS",1003=>"饿了么",1004=>"群脉商城");
    public static $_tip= [
        0 => 0,
        2 => 2,
        3 => 3,
        5 => 5,
        6 => 6,
        10 => 10,
        15 => 15,
        20 => 20,
        30 => 30,
        50 => 50,
        100 => 100,
    ];


    # 参考状态
     # news 表   status = 3 = 门店指派时状态 发送给对应骑手
     # news 表   status = 7 = 门店取消时状态 发送给对应骑手
     # news 表   status = 9 = 后台推送普通时状态 发送给所有骑手
     # news 表   ico  = 1 = 未读消息



    public static $_au = array(
        1 => array(
            array(0, '', '账号管理', array(
                    array(1, '?md=manage&cl=index&at=admingroup', '权限管理'),
                    array(1, '?md=manage&cl=index&at=admin', '账号管理'),
                    array(1, '?md=manage&cl=index&at=changepwd', '修改密码'),
                )),
            array(0, '', '门店管理', array(
                array(1, '?md=manage&cl=store&at=storelist', '门店列表'),
                array(1, '?md=manage&cl=store&at=company', '分司管理'),
            )),
            array(0, '', '商品重量管理', array(
                array(1, '?md=manage&cl=goods&at=goodsWeight', '商品重量列表'),
            )),
            array(0, '', '订单管理', array(
                array(1, '?md=manage&cl=order&at=orderlist', '订单列表'),
                array(1, '?md=manage&cl=order&at=orderErrorList', '异常订单'),
                array(1, '?md=manage&cl=order&at=orders_del', '已删订单'),
            )),

            array(0, '', '统计管理', array(
                array(1, '?md=manage&cl=statistics&at=companyRankingList', '分司排行'),
                array(1, '?md=manage&cl=statistics&at=storeRankingList', '门店订单排行'),
                array(1, '?md=manage&cl=statistics&at=ridersRankingList', '骑手配送排行'),
            )),
            array(0, '', '骑手管理', array(
                array(1, '?md=manage&cl=riders&at=riderslist', '骑手列表'),
                array(1, '?md=manage&cl=riders&at=riders_audit_list', '待审核列表'),
                array(1, '?md=manage&cl=riders&at=riders_no_pass_list', '审核未通过列表'),
                array(1, '?md=manage&cl=riders&at=riders_freight_list', '骑手运费列表'),
            )),

            array(0, '', '操作日志', array(
                array(1, '?md=manage&cl=index&at=log', '操作日志'),
                array(1, '?md=manage&cl=index&at=hybrislog', 'Hybris连线'),
            )),

            array(0, '', '前台管理', array(
                array(1, '?md=manage&cl=front&at=question_list', '前台问题列表'),
                array(1, '?md=manage&cl=front&at=message_cent', '消息中心'),
            )),

        ),
         2 => array(
             array(1, '?md=shop&cl=shop&at=orders', '未指派订单'),
             array(1, '?md=shop&cl=shop&at=unpush', '未推送订单'),
             array(1, '?md=shop&cl=shop&at=storelist', '待骑手接单'),
             array(1, '?md=shop&cl=shop&at=waitingpickup', '待取货订单'),
             array(1, '?md=shop&cl=shop&at=delivery', '配送中订单'),
             array(1, '?md=shop&cl=shop&at=delivery_finish', '配送完成订单'),
             array(1, '?md=shop&cl=shop&at=errorlist', '异常订单'),
             array(1, '?md=shop&cl=shop&at=horselist', '骑手管理'),
             array(1, '?md=shop&cl=shop&at=horse_freight', '骑手运费讯息'),
             array(1, '?md=shop&cl=shop&at=orders_del', '已删除订单'),
         ),
        3 => array(
            array(0, '', '账号管理', array(
                array(1, '?md=company&cl=company&at=changepwd', '修改密码'),
            )),
            array(0, '', '门店管理', array(
                array(1, '?md=company&cl=store&at=storelist', '门店列表'),
            )),
            array(0, '', '订单管理', array(
                array(1, '?md=company&cl=order&at=orderlist', '订单列表'),
                array(1, '?md=company&cl=order&at=orderErrorList', '异常订单'),
                array(1, '?md=company&cl=order&at=orders_del', '已删除订单'),
            )),

            array(0, '', '统计管理', array(
                array(1, '?md=company&cl=statistics&at=storeRankingList', '门店订单排行'),
                array(1, '?md=company&cl=statistics&at=ridersRankingList', '骑手配送排行'),
            )),
            array(0, '', '骑手管理', array(
                array(1, '?md=company&cl=riders&at=riderslist', '骑手列表'),
                array(1, '?md=company&cl=riders&at=riders_audit_list', '待审核列表'),
                array(1, '?md=company&cl=riders&at=riders_no_pass_list', '审核未通过列表'),
                array(1, '?md=company&cl=riders&at=riders_freight_list', '骑手运费列表'),
            )),

        ),


        4 => array(
            array(0, '', '账号管理', array(
                array(1, '?md=store&cl=shop&at=changepwd', '修改密码'),
            )),
            array(0, '', '订单管理', array(
                array(1, '?md=store&cl=order&at=orderlist', '订单列表'),
                array(1, '?md=store&cl=order&at=orderErrorList', '异常订单'),
                array(1, '?md=company&cl=order&at=orders_del', '已删除订单'),

            )),
            array(0, '', '骑手管理', array(
                array(1, '?md=store&cl=riders&at=riderslist', '骑手列表'),
                array(1, '?md=store&cl=riders&at=riders_audit_list', '待审核列表'),
                array(1, '?md=store&cl=riders&at=riders_no_pass_list', '审核未通过列表'),
                array(1, '?md=store&cl=riders&at=riders_freight_list', '骑手运费列表'),
            )),

        ),

    );

    static function getLeftMenu($role, $auth = '',$activityStatus = '') {

        $query_string = $_GET["at"];
        $breadcrumb_add = strpos($query_string, 'add');
        $query_string = str_replace('add', '', $query_string);
        $query_string = str_replace('edit', '', $query_string);
        $query_string = str_replace('_check', '', $query_string);

        $query_string_cl = $_GET["cl"];
        $login_page = '';
        $is_adm = strlen($auth) <= 0;
        $auth = strlen($auth) > 0 ? preg_split('/\s/', $auth) : array();
        $arrs = Data::$_au[$role];
        $data = '';
        $breadcrumb = '';
        $breadcrumb_current='';
        $menu_index = 0;
        if (count($arrs) > 0)
            foreach ($arrs as $i => $a) {
                $pstr = $role . '_' . $i;
                if (!in_array($pstr, $auth) && count($a[3]) <= 0 && !$is_adm && $a[0] != 2)
                    continue;
                $treeview_icon = count($a[3]) > 0 ? '<i class="fa fa-angle-left pull-right"></i>' : '';
                $treeview = count($a[3]) > 0 ? 'treeview' : '';
                $link_icon = '<i class="glyphicon glyphicon-th-list fa fa-link fa' . ($i + 1) . '"></i>';
                $focus = '';
                // 活动开启提醒开始
                if($a[2] == '红包触发'){
					if (isset($a[3]) && count($a[3]) > 0){
						foreach ($a[3] as $key => $value){
							$a[3][$key][2] = $activityStatus[$value[2]]?$value[2]."(".$activityStatus[$value[2]].")":$value[2];
						}
					}
                }
                // 活动开启提醒结束
                if (count($a[3]) > 0) {
                    foreach ($a[3] as $j => $b) {
                        $b1splite = array();
                        $b1splite = preg_split("/&/", $b[1]);

                        if (count($b1splite) > 1) {
                            $b1splite2 = array();
                            $b1splite2 = preg_split("/=/", $b1splite[2]);
                            $b1splite1 = preg_split("/=/", $b1splite[1]);
                            if (count($b1splite2) > 1) {
                                if (is_array($b1splite2) && $b1splite2[1] == $query_string && $b1splite1[1] == $query_string_cl) {
                                    $focus = 'active';
                                    break;
                                }
                            }
                        }
                    }
                } else {
                    $a1splite = array();
                    if (strpos($a[1],"cl=".$query_string_cl."&at=".$query_string)>-1){
                        $focus = 'active';
                    }
                }

                $href_breadcrumb = '<a href="' . (strlen($a[1]) > 0 ? $a[1] : '#') . '"><i class="fa fa-dashboard"></i><span>' . $a[2] . '</span>' . $treeview_icon . '</a>';
                $href = '<a href="' . (strlen($a[1]) > 0 ? $a[1] : '#') . '">' . $link_icon . '<span>' . $a[2] . '</span>' . $treeview_icon . '</a>';
                $h3 = '<li class="' . $treeview . ' ' . $focus . '">' . $href;
                $li = '';
                if (strlen($login_page) <= 0 && (strlen($a[1]) > 0 && strpos($a[1], 'logout') == false))
                    $login_page = $a[1];

                if (count($a[3]) > 0) {
                    foreach ($a[3] as $j => $b) {
                        $str = $role . '_' . $i . '_' . $j;

                        if (!(($b[0] == 1 && in_array($str, $auth)) || $is_adm || $b[0] == 2))
                            continue;
                        if (strlen($login_page) <= 0 && (strlen($b[1]) > 0 && strpos($b[1], 'logout') == false))
                            $login_page = $b[1];
                        $href = strlen($b[1]) > 0 ? '<a href="' . $b[1] . '"><span>' . $b[2] . '</span></a>' : $b[2];
                        $focus = '';
                        $b1splite = array();
                        $b1splite = preg_split("/&/", $b[1]);
                        if (count($b1splite) > 1) {
                            $b1splite2 = array();
                            $b1splite2 = preg_split("/=/", $b1splite[2]);
                            $b1splite1 = preg_split("/=/", $b1splite[1]);
                            //print_r($b1splite2);
                            //echo '$query_string:'.$query_string.', $query_string_cl:'.$query_string_cl.'<br/>';
                            if (count($b1splite2) > 1) {
                                if (is_array($b1splite2) && $b1splite2[1] == $query_string && $b1splite1[1] == $query_string_cl) {
                                    $breadcrumb = '<li>' . $a[2] . '</li> <li>' . $href . '</li>';
                                    $menu_index = $i;
                                    $focus = ' class="active"';
                                    $breadcrumb_current='<span class="current">'.$b[2].'</span>';
                                }
                            }
                        }

                        $li.='<li ' . $focus . '>' . $href . '</li>';
                    }
                } else {

                    $b1splite = preg_split("/\"/", $href_breadcrumb);
                    $b1splite = preg_split("/&/", $b1splite[1]);
                    if (($b1splite[2] == "at=" . $query_string) && ($b1splite[1] == "cl=" . $query_string_cl)) {
                        $breadcrumb = '<li>' . $href_breadcrumb . '</li>';
                    }

                }

                $data.=((in_array($pstr, $auth) || strlen($li) > 0 || $is_adm || $a[0] == 2) ? $h3 : '') . (strlen($li) > 0 ? '<ul class="treeview-menu">' . $li . '</ul></li>' : '');
            }

        $breadcrumb .=($breadcrumb_add > -1 ) ? '<li class="active">' . ((!empty($_GET['id']) && ($_GET['id'] > 0)) > 0 ? '%{EDIT}%' : '%{ADD}%') . '</li>' : '';
        $breadcrumb = strlen($breadcrumb) > 0 ? '<ol class="breadcrumb">' . $breadcrumb . '</ol>' : '';
        return array('list' => '<ul class="sidebar-menu">' . $data . '</ul>', 'login_page' => $login_page, 'breadcrumb' => $breadcrumb, 'breadcrumb_current'=>$breadcrumb_current,'menu_index' => $menu_index);
    }

    public static function getAuthList($role, $auth) {
        $auth = strlen($auth) > 0 ? preg_split('/\s/', $auth) : array();
        $list = array('op' => array(), 'br' => array(), 'ck' => array());
        $arrs = Data::$_au[$role];
        if (count($arrs) > 0)
            foreach ($arrs as $i => $a) {
                if ($a[0] == 1) {
                    $str = $role . '_' . $i;
                    $list['op'][$str] = $a[2];
                    array_push($list['br'], 1);
                    array_push($list['ck'], in_array($str, $auth) ? 1 : 0);
                }
                foreach ($a[3] as $j => $b) {
                    if ($b[0] == 1) {
                        $str = $role . '_' . $i . '_' . $j;
                        $list['op'][$str] = $b[2];
                        array_push($list['br'], 1);
                        array_push($list['ck'], in_array($str, $auth) ? 1 : 0);
                    }
                }
            }
        return $list;
    }

    public static function getAllAuthList($role) {
        $arrs = Data::$_au[1];
        if (count($arrs) > 0) {
            foreach ($arrs as $i => $a) {
                $str = $role . '_' . $i;
                $list[$str] = array('name' => $a[2]);
                if (count($a[3]) > 0) {
                    foreach ($a[3] as $j => $b) {
                        if ($b[0] == 1) {
                            $str_2 = $role . '_' . $i . '_' . $j;
                            $list[$str]['sub'][$str_2] = $b[2];
                        }
                    }
                }
            }
        }
        return $list;
    }

    public static function getSalt($length) {
        $str = '023167981204984023165798641032498796131234567890';
        $l = strlen($str);
        $salt = '';
        for ($index = 0; $index <= $length; $index++) {
            $salt .= $str[rand(0, $l)];
        }
        return $salt;
    }

}

?>
